import info.gridworld.actor.Actor;
import info.gridworld.actor.Critter;
import info.gridworld.grid.Grid;
import info.gridworld.grid.Location;

import java.awt.Color;
import java.util.ArrayList;

/**
 * A <code>QuickCrab</code> looks at a limited set of neighbors when it eats and moves.
 * <br />
 * This class is not tested on the AP CS A and AB exams.
 */
public class QuickCrab extends CrabCritter
{
    public QuickCrab()
    {
        setColor(Color.BLUE);
    }

    
    /**
     * @return list of empty locations immediately to the right and to the left
     */
    public ArrayList<Location> getMoveLocations()
    {
        ArrayList<Location> locs = new ArrayList<Location>();
        checkTwoAwayMove(locs, getDirection() + Location.LEFT);
        checkTwoAwayMove(locs, getDirection() + Location.RIGHT);
        if (locs.isEmpty())
        {
        	return super.getMoveLocations();
        }
        return locs;
    }
    
    /**
     * check next two steps of the direction
     * @param locs
     * @param dir
     */
    private void checkTwoAwayMove(ArrayList<Location> locs, int dir)
    {
    	Grid gird = getGrid();
    	Location loc = getLocation().getAdjacentLocation(dir);
    	
    	if (gird.isValid(loc) && gird.get(loc) == null)
    	{
    		Location n_loc = loc.getAdjacentLocation(dir);
    		if (gird.isValid(n_loc) && gird.get(n_loc) == null)
    		{
    			locs.add(n_loc);
    		}
    	}
    	
    }
    
    
}
